#!/bin/bash -e
# 
# File: stop.sh
# Purpose: stop autossh for tunnel sites
#

cd $(dirname "$0")
. ./common.sh

test "$1" && tunnelsites="$@" || tunnelsites=$(./sites.sh)

for tunnelsite in $tunnelsites; do
	
	if ! match_session $tunnel_name | awk '$0 !~ /tached/ { exit 1 }'; then
		tunnel_name=`echo ${tunnelsite} | cut -d = -f 1`;
		info stopping $tunnel_name ...		
		screen -S $tunnel_name -wipe >/dev/null || :
		#screen -S $tunnelsite -p 0 -X stuff 
	fi

done
